<%@ page language="java" %>

<%@ page import="java.util.*,
                 java.net.*,
                 java.lang.*,
                 com.broadvision.ssp.client.SspInstance,
                 com.broadvision.web.util.ViewDynaBean,
		 org.apache.struts.validator.DynaValidatorForm,
                 org.apache.commons.beanutils.PropertyUtils"
%>

<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<jsp:useBean id="contentSearchResultView" scope="request" type="com.broadvision.web.util.ViewDynaBean"/> 
<bean-el:size id="resultSize" name="contentSearchResultView" property="resultList"/>

<% 
   String ctxPath = request.getContextPath(); 
   ViewDynaBean view = (ViewDynaBean) request.getAttribute("contentSearchResultView"); 
   Integer totalCount = (Integer) PropertyUtils.getSimpleProperty(view, "totalCount");
%>
   
<script language="javascript" src="<%=request.getContextPath()%>/mt/js/date.js"></script>
<script language="javascript" src="<%=request.getContextPath()%>/bp/js/user_popup_funcs.js"></script>

<script language="javascript">


 function doBVAction(theForm,cntOID,cntTypeId,catOID,cntAction){
   var theURL="/cm/cmBVCProcessMapping.do";
   var theParam="?contentOID="+cntOID+"&categoryOID="+catOID+"&contentTypeId="+cntTypeId+"&contentAction="+cntAction+"&exitURL=/cm/closeWindowOnly.do";
   var url ='<html-el:rewrite page="'+theURL+'" />'+theParam;
   var qualifier = window.open(url, "ContentServiceLaunchProcess",
                              "directories=no,height=500,width=650,left=50,top=50,resizable=yes,scrollbars=yes,location=yes,menubar=yes,status=yes,toolbar=yes");

   if (qualifier != null){
     if (qualifier.opener == null)
         qualifier.opener = self;
    qualifier.focus();
  }
 }

function doGoCnt(formName) {
  var thisForm = document.forms[formName];
  if (thisForm != null) {
     thisForm.pageNum.value = 1;
     var theURL = "/cm/cmBVContentSearch.do?action=doGoCnt"
     thisForm.action = '<html-el:rewrite page="'+theURL+'" />';
     thisForm.submit();
  } 
  return false;
}

function gotoPage(formName, pageNum) {
  var thisForm = document.forms[formName];
  if (thisForm != null) {
     thisForm.pageNum.value = pageNum;
     var theURL = "/cm/cmBVContentSearch.do?action=gotoPage"
     thisForm.action = '<html-el:rewrite page="'+theURL+'" />';
     thisForm.submit();
  } 
}

function setRuntimeAction(theForm) {
  theForm.curVersion[0].disabled=true;
  theForm.curVersion[1].disabled=true;
  theForm.sortBy.disabled= "checked";
  return true;
}
function onSubmit(myform) {

  if (myform.cntTypeId.value == "-1"){
     alert('<bean-el:message bundle="cm.messages" key="cm.content.search.selectcontenttype"/>');
     return false;
  }

  var temp = myform.contentKey.value;
  myform.contentKey.value = temp.stringTrim();
  if (myform.contentKey.value == 0){
     alert('<bean-el:message bundle="cm.messages" key="cm.content.search.nocriteria"/>');
     return false;
   }
   var date = getDateOnly("cmBVContentSearchForm", "lastModDate");

   if (myform.includeLastModDate.checked && date == null) {
     alert('<bean-el:message bundle="cm.messages" key="cm.content.search.lastmoddate"/>');
     return false;
   }
   myform.submit();
   return true;
}
function doRefresh() {
  return onSubmit(document.forms["cmBVContentSearchForm"]);
}



</script>

<%@include file="/mt/common/pickerPopupHelper.jsp" %>
<jsp:useBean id="cmCntTypeListViewSearch" scope="session" type="com.broadvision.web.util.ViewDynaBean"/>

<jsp:useBean id="cmContentAdmin" scope="session" type="java.lang.Boolean"/>

<html-el:form action="/cm/cmBVContentSearch.do?action=search">
<html-el:hidden property="pageNum" value="1" />
<input type="hidden" name="contentOid"/>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean-el:message bundle='cm.messages' key='cm.content.advSearch'/>">

  <tr> 
  <td valign="top" width="100%">
		  
  <div class="pageTitle"><bean-el:message bundle='cm.messages' key='cm.content.advSearch'/></div>

<%@include file="/mc/common/pagetab.jsp" %>
  <div class="pageSubtitle">
    <span class="left"><bean-el:message bundle='cm.messages' key='cm.content.searchCriteria'/></span>
    <span class="right">&nbsp;</span>
  </div> 
           
  <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean-el:message bundle='cm.messages' key='cm.content.advSearch'/>">
         
  <!--start main content here-->
 
     <tr>
       <td width="20%" class="label"><bean-el:message bundle='cm.messages' key='cm.browse.type'/>:</td>
       <!-- td class="labelField" width="60%" -->
       <td class="labelField" width="50%">
         <c:set var="cntList" scope="page" value="${cmCntTypeListViewSearch.map.cntTypeList}"/>
         <html-el:select name="cmBVContentSearchForm" property="cntTypeId" > 
           <html-el:options collection="cntList" property="id" labelProperty="name" />
         </html-el:select>
       </td>
     </tr>

    <tr>
      <td valign="top" width="20%" class="label"> 
        <bean-el:message bundle="cm.messages" key="cm.content.search.searchstring"/>: 
      </td>
      <td valign="top" class="labelField" width="50%" >
        <html-el:radio property="stringSearchOption" value="startWith" />
        <bean-el:message bundle='cm.messages' key='cm.content.search.startwith'/>&nbsp;
        <html-el:radio property="stringSearchOption" value="contains"  /> 
        <bean-el:message bundle='cm.messages' key='cm.content.search.contains' /> &nbsp;
        <html-el:text name="contentSearchResultView" property="contentKey" maxlength="100" size="50" />
      </td>
    </tr>

    <tr>
      <td valign="top" width="20%" class="label"> 
        <bean-el:message bundle="cm.messages" key="cm.content.search.contentstatus"/>: 
      </td>

      <td valign="top" class="labelField" width="50%">
        <html-el:checkbox property="contentOnline" value="1" />
        <bean-el:message bundle='cm.messages' key='cm.content.search.online'/>&nbsp;
        <html-el:checkbox property="contentOffline" value="1" />
        <bean-el:message bundle='cm.messages' key='cm.content.search.offline' /> &nbsp;
      </td>
    </tr>

    <tr>
      <td valign="top" width="20%" class="label"><bean-el:message bundle="cm.messages" key="cm.content.contentModificationDate"/>:</td>
      <td valign="top" width="50%" class="labelField" nowrap>
        <html-el:checkbox property="includeLastModDate" value="1"/>
        <bvhtml:date name="contentSearchResultView" property="lastModDate"
          onChangeMonth="onChangeMonth" onChangeYear="onChangeYear"/>
        <a href="JavaScript:datePopup(
          '<html-el:rewrite page="/cm/calendar.do"/>', 'cmBVContentSearchForm','lastModDate')">
          <img src="<%= ctxPath %>/mc/images/action/calendar.gif" width="22" height="22"
            alt="<bean-el:message bundle="cm.messages" key="cm.process.processInstanceSearch.chooseDate" />"
            border="0" align="absmiddle"/>
        </a>                             
      </td>
    </tr>
        
  </table>
  <div class="pageButtonWrap" align="right">
   <input type="button" name="results" class="inputButton"  onClick="return onSubmit(this.form)"
                value="<bean-el:message bundle='cm.messages' key='button.showResults'/>">
  </div>  
      
  <br>

<c:if test="${contentSearchResultView.map.searchResultMsg== 'ShowResults'}">  

  <div class="pageSubtitle">
    <span class="left"><bean-el:message bundle='cm.messages' key='cm.content.search.searchResultFound' arg0="<%= totalCount.toString() %>" /></span>
    <span class="right">&nbsp;</span>
  </div>

  <table class="dataTable" border="0" cellspacing="1" cellpadding="2" width="100%" summary="<bean-el:message bundle='cm.messages' key='cm.content.search.resultList'/>">
  <tr class="listHeader"> 
    <th id="Content Name" align="left"><bean-el:message bundle='cm.messages' key='cm.content.contentName'/></th>
    <th id="Creation Time" align="left"><bean-el:message bundle='cm.messages' key='cm.content.search.creationtime'/></th>
    <th id="Last Modification Time" align="left"><bean-el:message bundle='cm.messages' key='cm.content.search.lastmodtime'/></th>
    <th id="Action" align="left"><bean-el:message bundle='cm.messages' key='cm.content.search.action'/></th>
  </tr>     
  
  <c:if test="${resultSize == '0'}">
  <tr class="listEven"> 
    <td colspan="8" valign="top" align="center"><bean-el:message bundle='cm.messages' key='cm.content.noContentFound'/></td>
  </tr>
  </c:if>

 <c:forEach var="result" items="${contentSearchResultView.map.resultList}" varStatus="status"> 
   <c:choose>
     <c:when test="${(status.count+1) % 2 == 0}">
           <tr class="listEven">
     </c:when>
         <c:otherwise>
           <tr class="listOdd">
         </c:otherwise>
   </c:choose>
      <td headers="Content Name" align="left">
      <a href="JavaScript:doBVAction(document.cmBVContentSearchForm,'<c:out value="${result.map.oid}"/>','<c:out value="${result.map.cntTypeId}"/>','','ViewContent')" >
	  <c:out value="${result.map.name}"/> </a>
      </td>
      <td headers="Creation Time" align="left">
	  <c:out value="${result.map.createtime}"/>
      </td>
      <td headers="Last Modification Time" align="left">
	  <c:out value="${result.map.lastmodtime}"/>
      </td>
      <td headers="Action" align="left" nowrap>
      <a href="JavaScript:doBVAction(document.cmBVContentSearchForm,'<c:out value="${result.map.oid}"/>','<c:out value="${result.map.cntTypeId}"/>','','ViewContent')" >
      <img src="<%=ctxPath%>/mc/images/action/icon_view.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.view"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.view"/>'></a>
      <a href="JavaScript:doBVAction(document.cmBVContentSearchForm,'<c:out value="${result.map.oid}"/>','<c:out value="${result.map.cntTypeId}"/>','','EditContent')" >
      <img src="<%=ctxPath%>/mc/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.edit"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.edit"/>'></a>
      <a href="JavaScript:doBVAction(document.cmBVContentSearchForm,'<c:out value="${result.map.oid}"/>','<c:out value="${result.map.cntTypeId}"/>','','DeleteContent')" >
      <img src="<%=ctxPath%>/mc/images/action/icon_delete.gif" width="15" height="15" border="0" class="actionIcon" alt='<bean-el:message bundle="cm.messages" key="image.alt.delete"/>' title='<bean-el:message bundle="cm.messages" key="image.alt.delete"/>'></a>
      </td>
    </tr>

   </c:forEach>
  </table>


</c:if> <!-- showResult -->

<c:if test="${contentSearchResultView.map.pagination == '1'}">
   
  <div class="pagination">
    <bean-el:message key="cm.common.pagination.show" bundle="cm.messages"/>
      <html-el:select property="entriesPerPage" size="1" onchange="doGoCnt('cmBVContentSearchForm')">
        <html-el:option value="10">10</html-el:option>
        <html-el:option value="20">20</html-el:option>
        <html-el:option value="30">30</html-el:option>
        <html-el:option value="50">50</html-el:option>
        <html-el:option value="100">100</html-el:option>
      </html-el:select>
      <bean-el:message key="cm.common.pagination.itemsPerPage" bundle="cm.messages"/>
      &nbsp;&nbsp; 
   <% 
     Integer currentPageNumberInt = (Integer) PropertyUtils.getSimpleProperty(view, "currPageNum"); 
     Integer totalPageNumberInt = (Integer) PropertyUtils.getSimpleProperty(view, "totalPageNum"); 
   %>
   

 <c:if test="${contentSearchResultView.map.currPageNum >1}">  
    <a href="#" class="paginationBtn" onclick="javascript:gotoPage('cmBVContentSearchForm', 1)"><bean-el:message bundle='cm.messages' key='cm.common.pagination.first'/></a>
    <a href="#" class="paginationBtn" onclick="javascript:gotoPage('cmBVContentSearchForm', <%= currentPageNumberInt.intValue()-1 %>)"><bean-el:message bundle='cm.messages' key='cm.common.pagination.previous'/></a>
  </c:if>

  <bean-el:message bundle='cm.messages' key='cm.common.pagination.pageOf' arg0="<%= currentPageNumberInt.toString() %>" arg1="<%= totalPageNumberInt.toString() %>"/>

 <c:if test="${contentSearchResultView.map.currPageNum < contentSearchResultView.map.totalPageNum}">  
    <a href="#" class="paginationBtn" onclick="javascript:gotoPage('cmBVContentSearchForm', <%= currentPageNumberInt.intValue()+1 %>)"><bean-el:message bundle='cm.messages' key='cm.common.pagination.next'/></a>
    <a href="#" class="paginationBtn" onclick="javascript:gotoPage('cmBVContentSearchForm', <%= totalPageNumberInt.intValue() %>)"><bean-el:message bundle='cm.messages' key='cm.common.pagination.last'/></a>
  </c:if>
  </div>
</c:if>

 </td>
 </tr>
   </table>
 </html-el:form>


